#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QMessageBox>
#include <QDateTime>
#include <QTimer>
#include <QComboBox>
#include <QPushButton>
#include <QCheckBox>
#include <QSpinBox>
#include <QTextEdit>
#include <QLabel>
#include <QGroupBox>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QStatusBar>
#include <QSplitter>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void onOpenSerialPort();
    void onCloseSerialPort();
    void onSendData();
    void onReadData();
    void onRefreshPorts();
    void onClearReceiveData();
    void onClearSendData();
    void onAutoSendToggled(bool checked);

private:
    void createUI();
    void setupConnections();
    void updatePortsInfo();
    void showStatusMessage(const QString &message);
    void appendToReceiveText(const QString &text, bool isHex = false);

private:
    // 串口设置控件
    QComboBox *portComboBox_;
    QComboBox *baudRateComboBox_;
    QComboBox *dataBitsComboBox_;
    QComboBox *parityComboBox_;
    QComboBox *stopBitsComboBox_;
    QComboBox *flowControlComboBox_;
    QPushButton *openPortButton_;
    QPushButton *closePortButton_;
    QPushButton *refreshPortsButton_;
    
    // 发送区控件
    QTextEdit *sendTextEdit_;
    QPushButton *sendButton_;
    QPushButton *clearSendButton_;
    QCheckBox *hexSendCheckBox_;
    QCheckBox *autoSendCheckBox_;
    QSpinBox *autoSendIntervalSpinBox_;
    
    // 接收区控件
    QTextEdit *receiveTextEdit_;
    QPushButton *clearReceiveButton_;
    QCheckBox *hexDisplayCheckBox_;
    QCheckBox *autoScrollCheckBox_;
    
    // 串口和定时器
    QSerialPort serialPort_;
    QTimer autoSendTimer_;
    
    // 状态标志
    bool isHexDisplay_;
    bool isHexSend_;
};
#endif // MAINWINDOW_H
